﻿Public Class CReportSet_Screen2 : Inherits CStateBase

    ''' <summary>
    ''' 実行可能かを判断する
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function IsEnter(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CReportSet_Screen2.IsEnter")
        If CCommon.isInStr(task.ActionCd, "REPORTLIST_MODE") Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 出荷情報絞るリスト画面
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExecute(ByVal task As CTaskBase) As CStateBase
        Dim nextState As CStateBase = Nothing
        Dim pdaTask As CPDATask2 = DirectCast(task, CPDATask2)
        Dim webMng As CWebManager = CWebManager.GetInstance
        Dim AppManager As CApplicationManager = CApplicationManager.GetInstance

        'Dim waitTask As CPersonal = New CPersonal(pdaTask)
        Debug.WriteLine("CReportSet_Screen2.DoExecute...START")

        Dim StateDao As CMasterDAO = New CMasterDAO
        Dim app As CApplication = CApplication.GetInstance()
        Dim masterDao As New CMasterDAO
        Dim sql As CSQLite = app.MasterDB()
        Dim trx As CTransaction = sql.GetTransaction

        Try
            '読んだラベルをチェック
            Dim retSetCdLst As ArrayList = StateDao.GetSetCdList(trx, task.ProcessText)


            'SET_CDが複数かどうかの判別(普通のパタン)----------------------①-1SET_CDの件数
            If retSetCdLst.Count = 1 Then
                CCommon.FlagManage("ORDER_COMMIT", True)
                Select Case CEventCheck.SetCdCheck(pdaTask, retSetCdLst)

                    Case 0
                        pdaTask.WindowManager.ChangeWindowMode(EnumWindowMode.LIST_MODE)
                        '初期化-------------------------->>START
                        CEventCheck.initErrPdaTask(pdaTask)
                        '初期化-------------------------->>END
                        'エラーメッセージ表示
                        CPersonal.ErrorWindow2(pdaTask, EnumWindowMode.ALERT_MODE, _
                                            Color.Black, CConst.EnumSound.ALERT_BUZZ, "別のラベルセットです。", Color.White)

                    Case 1
                        '正常
                        'もし、ORDER_CDとSET_CDがあればそのままINSERTにする------------------------>>>>>>>>
                        'MessageBox.Show("pdaTask.OrderCd:" & pdaTask.OrderCd)
                        If pdaTask.OrderCd <> "" And pdaTask.SetCd <> "" Then
                            '注文のデータと読んだラベルと比べる
                            If CPersonal.ChkOrderDataSetCd(pdaTask) Then
                                'INSERTする前確認
                                If CPersonal.INSERT_ADD_LABEL(pdaTask) Then

                                    '初期化-------------------------->>START
                                    CEventCheck.initInsertPdaTask(pdaTask)
                                    '初期化-------------------------->>END
                                    pdaTask.WindowManager.ChangeWindowMode(EnumWindowMode.LIST_MODE)
                                    '完全に照合成功
                                    pdaTask.Hardware.nextC()

                                Else
                                    'INSERT失敗
                                    '既に使用済みのもの
                                    '初期化-------------------------->>START
                                    CEventCheck.initErrPdaTask(pdaTask)
                                    pdaTask.WindowManager.ChangeWindowMode(EnumWindowMode.LIST_MODE)

                                End If

                            Else
                                '先、注文番号を選択して他のラベル読んだ時点
                                '選択解除
                                Dim listCount As Integer = pdaTask.WindowManager.GetRecordCount()
                                For cn As Integer = 0 To listCount - 1
                                    Dim setline As COrderRecord = pdaTask.WindowManager.GetRecord(cn)
                                    If setline.OrderCd = pdaTask.OrderCd Then
                                        setline.RowColor = Color.White
                                        setline.IsSelectFlg = False
                                        Exit For
                                    End If
                                Next
                                '初期化-------------------------->>START
                                CEventCheck.initErrPdaTask(pdaTask)
                                '初期化-------------------------->>END
                                'MessageBox.Show("1")
                                'エラーメッセージ表示
                                CPersonal.ErrorWindow2(pdaTask, EnumWindowMode.ALERT_MODE, _
                                                    Color.Black, CConst.EnumSound.ALERT_BUZZ, CConst.CNS_MSG_007, Color.White)

                            End If
                            'もし、ORDER_CDとSET_CDがあればそのままINSERTにする------------------------>>>>>>>>
                        End If

                End Select

            ElseIf retSetCdLst.Count > 1 Then

                '選択したらFalseなら選択してもラベル読む感じするように
                CCommon.FlagManage("ORDER_COMMIT", False)

                'MessageBox.Show("ListReportFlg:TRUE")
                Dim ErrorFlg As Boolean = True
                For i As Integer = 0 To retSetCdLst.Count - 1
                    Dim SearchLblData As ArrayList = StateDao.GetOrderDataLst(trx, retSetCdLst(i))
                    For j As Integer = 0 To SearchLblData.Count - 1
                        Dim labelData As CPersonal.strctNowLabelState = SearchLblData(j)
                        '配列の中にデータがなければ
                        If pdaTask.ReportDataUni.Contains(labelData) Then
                            ErrorFlg = False
                            Exit For
                        End If
                    Next
                Next
                If ErrorFlg Then
                    '初期化-------------------------->>START
                    CEventCheck.initErrPdaTask(pdaTask)
                    '初期化-------------------------->>END
                    'MessageBox.Show("3")
                    'エラーメッセージ表示
                    CPersonal.ErrorWindow2(pdaTask, EnumWindowMode.ALERT_MODE, _
                                        Color.Black, CConst.EnumSound.ALERT_BUZZ, CConst.CNS_MSG_007, Color.White)
                End If

            Else
                '初期化-------------------------->>START
                CEventCheck.initErrPdaTask(pdaTask)
                '初期化-------------------------->>END
                'エラーメッセージ表示
                CPersonal.ErrorWindow2(pdaTask, EnumWindowMode.ALERT_MODE, _
                                    Color.Black, CConst.EnumSound.ALERT_BUZZ, "別のラベルセットです。", Color.White)

            End If

        Catch ex As Exception
            'MessageBox.Show("CReportエラー:" & ex.Message)
        End Try

        task.ActionCd = "LABEL"
        task.ProcessText = ""
        nextState = GetNextState(task)
        Return nextState
    End Function

    ''' <summary>
    ''' 終了メソッド(未使用)
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExit(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CReportSet_Screen2.DoExit")
        Return True
    End Function


End Class
